package com.briup.cms.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.briup.cms.domain.Comment;
import com.briup.cms.domain.Subcomment;
import com.briup.cms.domain.param.CommentQueryParam;
import com.briup.cms.service.ISubcommentService;
import com.briup.cms.util.Result;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author briup
 * @since 2023-03-09
 */
@RestController
@RequestMapping("/subcomment")
public class SubcommentController {
    @Autowired
    ISubcommentService subcommentService;

    @ApiOperation("添加二级评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "subcomment",value = "二级评论")
    })
    @PostMapping("/addComment")
    public Result addComment(@RequestBody Subcomment subcomment){
        subcommentService.addSubComment(subcomment);
        return Result.success();
    }

    @ApiOperation("删除二级评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "删除id")
    })
    @GetMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        subcommentService.deleteById(id);
        return Result.success();
    }

    @ApiOperation("根据父id查询评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId",value = "父id")
    })
    @GetMapping("/queryByParentId")
    public Result queryByParentId(Long parentId){
        List<Subcomment> subcomments = subcommentService.queryByParentId(parentId);
        return Result.success(subcomments);
    }

    @ApiOperation("查询二级评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param",value = "查询条件")
    })
    @PostMapping("/query")
    public Result query(CommentQueryParam param){
        IPage<Subcomment> query = subcommentService.query(param);
        return Result.success(query);
    }
}

